import jieba.posseg as psg
import jieba

jieba.load_userdict('./userdic.txt')
dict = {}

with open('news.txt',encoding='utf-8') as f:
    text = f.readlines()
    for t in text:
        res = psg.cut(t)
        for item in res:
            if item.flag == 'nr' and item.word in dict:
                dict[item.word] += 1
            elif item.flag == 'nr' and item.word not in dict:
                dict[item.word] = 1

name_count = sorted(dict.items(), key=lambda x : x[1], reverse=True)
print(name_count[:30])



